/**
 * Created by Administrator on 2018/1/25.
 */
myApp_.onPageInit('search', function (page) {
    //请求历史搜索数据
	use('index/search/search_history');
    SEARCH.get_history();
});

myApp_.onPageAfterAnimation('search', function (page) {
    SEARCH.get_history();
});


SEARCH = {};

SEARCH.is_load = false;
SEARCH.history = [];

SEARCH.__INIT__=function(){
    mainView.router.load({
        url: "src/index/search/search.html"
    });
}

SEARCH.get_history = function(){
	SEARCH.history = SEARCH_HISTORY.get();
	SEARCH.fill_history();
}

SEARCH.fill_history = function(){
	var data = SEARCH.history;
	
	tpl_fill(
		'{{#each this}}'+
		'<a onclick="SEARCH.do_search(\'{{this}}\')">{{this}}</a>'+
		'{{/each}}'
		,data
		,'.history_content'
	);
}

SEARCH.do_search = function(kw){
	if(!kw){
		kw = $('#search_ipt').val();
		if(!kw){
			my_tips_('请输入要搜索的商品');
			return false;
		}
	}
	
	//添加进搜索历史
	SEARCH_HISTORY.add(kw);
	
	kw = encodeURI(kw);
	go_('goods_list/'+kw);
}
